(function () {

	require.config({
		packages:[{
			name:'echarts',
			location:'/scripts/echarts',
			main:'echarts'
		}
		]
	});
	//饼图
	function initPieChart(elementId,mydata){
		var option = {
			    title : {
			        text: '工作室订单额度汇总',
//			        subtext: '工作室订单额度汇总',
			        x:'center'
			    },
			    tooltip : {
			        trigger: 'item',
			        formatter: "{a} <br/>{b} : {c} ({d}%)"
			    },
			    legend: {
			        orient : 'vertical',
			        x : 'left',
			        data:(legendData)(mydata)
//			        ['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']
			    },
			    toolbox: {
			        show : true,
			        feature : {
			            mark : {show: true},
			            dataView : {show: true, readOnly: false},
			            magicType : {
			                show: true, 
			                type: ['pie', 'funnel'],
			                option: {
			                    funnel: {
			                        x: '25%',
			                        width: '50%',
			                        funnelAlign: 'left',
			                        max: 10000000
			                    }
			                }
			            },
			            restore : {show: true},
			            saveAsImage : {show: true}
			        }
			    },
			    calculable : true,
			    series : [
			        {
			            name:'订单金额',
			            type:'pie',
			            radius : '55%',
			            center: ['50%', '60%'],
			            data:(seriesData)(mydata)
//			            	[
//			                {value:335, name:'直接访问'},
//			                {value:310, name:'邮件营销'},
//			                {value:234, name:'联盟广告'},
//			                {value:135, name:'视频广告'},
//			                {value:1548, name:'搜索引擎'}
//			            ]
			        }
			    ]
			};
		require(
				[
					'echarts',
					'echarts/chart/pie',
					'echarts/chart/funnel'
				],
				function(ec) {
					var myChart = ec.init(document.getElementById(elementId));
					myChart.setOption(option);
					window.onresize = myChart.resize;
				}
			);
			                    
	}
	function legendData(mydata){
		var dataArr = [];
		var data = mydata.data;
		for(var i=0;i<data.length;i++){
//			var dataObj = {};
//			dataObj.name = data[i].name;
//			dataObj.value = parseInt(myEventData[i].value);
//			dataArr.push(dataObj);
			dataArr.push(data[i].name);
		}
		return dataArr;
	}
	
	function seriesData(mydata){
		var data = mydata.data;
		return data;
	}
	function initPieChart2(elementId,mydata){
		var option = {
			    title : {
			        text: '工作室订单笔数汇总',
//			        subtext: '工作室订单笔数汇总',
			        x:'center'
			    },
			    tooltip : {
			        trigger: 'item',
			        formatter: "{a} <br/>{b} : {c} ({d}%)"
			    },
			    legend: {
			        orient : 'vertical',
			        x : 'left',
			        data:(legendData)(mydata)
			    },
			    toolbox: {
			        show : true,
			        feature : {
			            mark : {show: true},
			            dataView : {show: true, readOnly: false},
			            magicType : {
			                show: true, 
			                type: ['pie', 'funnel'],
			                option: {
			                    funnel: {
			                        x: '25%',
			                        width: '50%',
			                        funnelAlign: 'left',
			                        max: 200
			                    }
			                }
			            },
			            restore : {show: true},
			            saveAsImage : {show: true}
			        }
			    },
			    calculable : true,
			    series : [
			        {
			            name:'订单数量',
			            type:'pie',
			            radius : '55%',
			            center: ['50%', '60%'],
			            data:(seriesData)(mydata)
			        }
			    ]
			};
		require(
				[
					'echarts',
					'echarts/chart/pie',
					'echarts/chart/funnel'
				],
				function(ec) {
					var myChart = ec.init(document.getElementById(elementId));
					myChart.setOption(option);
					window.onresize = myChart.resize;
				}
			);
			                    
	}
	window["initPieChart"] = initPieChart;
	window["initPieChart2"] = initPieChart2;
})()